<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="学校" prop="zxmc">
        <el-select v-model="queryParams.zxmc" placeholder="请选择" clearable filterable size="small">
          <el-option
            v-for="dict in zxmcList"
            :key="dict.zxmc"
            :label="dict.zxmc"
            :value="dict.zxmc"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="准考号" prop="name">
        <el-input v-model="queryParams.zkh" placeholder="请输入准考号"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="candidateList">
      <el-table-column label="序号" type="index" align="center">
        <template slot-scope="scope">
          <span>{{scope.$index+(queryParams.pageNo-1)*queryParams.pageSize+1}}</span>
        </template>
      </el-table-column>
      <el-table-column label="准考号" align="center" prop="zkh"/>
      <el-table-column label="建档号" align="center" prop="jdh"/>
      <el-table-column label="姓名" align="center" prop="name"/>
      <el-table-column label="性别" align="center" prop="gender">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.gender"/>
        </template>
      </el-table-column>
      <el-table-column label="中学代码" align="center" prop="zxdm"/>
      <el-table-column label="中学名称" align="center" prop="zxmc"/>
      <el-table-column label="班级代码" align="center" prop="bjdm"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleDetail(scope.row)"
          >选择
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNo"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>
<style>
  h1, h2, h3, h4, h5, h6 {
    margin-top: 0;
    margin-bottom: 0.5em;
    color: rgba(0, 0, 0, .85);
    font-weight: 500;
  }
</style>
<script>
  import { candidates, examProjectsList, schoolClass } from '@/api/business/candidate/candidate'
  import { listSchool } from '@/api/business/school/school'

  export default {
    name: 'candidateList',
    dicts: ['sys_user_sex', 'pictureFlag'],
    data() {
      return {
        // 遮罩层
        loading: false,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 考生表格数据
        candidateList: [],
        candidateList2: [],
        // 弹出层标题
        title: '',
        detailTitle: '',
        updateTitle: '',
        // 是否显示弹出层
        open: false,
        detailOpen: false,
        updateOpen: false,
        // 查询参数
        queryParams: {
          pageNo: 1,
          pageSize: 10,
          zxmc: null,
          bjdm: null,
          pictureFlag: null
        },
        // 表单参数
        form: {},
        form2: {},
        zxmcList: [],
        bjdmList: [],
        pictureFlagList: [],
        projectIdList: [],
        doUpload: ''
      }
    },
    created() {
      this.candidateList=[];
      listSchool().then(response => {
        this.zxmcList = response.rows
      })
      schoolClass().then(response => {
        this.bjdmList = response.data
      })
      examProjectsList().then(response => {
        this.projectIdList = response.data
      })
    },
    methods: {
      /** 查询考生列表 */
      getList() {
        this.loading = true
        candidates(this.queryParams).then(response => {
          const records = response.data.records
          this.candidateList = records
          this.total = response.data.totalCount
          this.loading = false
          var j = 0
          this.candidateList2 = new Array(5)
          for (var i = 0; i <= records.length; i = i + 2) {
            if (records[i] == null) {
              break
            }
            const row = { 'one': null, 'two': null }
            row.one = records[i]
            row.two = records[i + 1]
            this.candidateList2[j] = row
            j++
          }
        })
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNo = 1
        this.getList()
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm('queryForm')
        this.handleQuery()
      },
      /** 详情按钮操作 */
      handleDetail(row) {
        this.$emit("listenToChildEvent",row);
      },
    }
  }
</script>
